package br.ufrj.dcc.tp.cliente.gui.event;

import javax.swing.JTextArea;
import javax.swing.JTextField;

public class MessageEvent implements Runnable {
	
	private JTextArea text;
	private JTextField field;
	private String message;
	private EventType e;
	
	public MessageEvent(JTextArea text, EventType e) {
		this.text = text;
		this.e = e;
	}
	
	public MessageEvent(JTextField field, String message, EventType e) {
		this.field = field;
		this.message = message;
		this.e = e;
	}
	
	public MessageEvent(JTextArea text, String message, EventType e) {
		this(text, e);
		this.message = message;
	}
	
	public JTextArea getText() {
		return text;
	}

	public void setText(JTextArea text) {
		this.text = text;
	}

	public JTextField getField() {
		return field;
	}

	public void setField(JTextField field) {
		this.field = field;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public EventType getE() {
		return e;
	}

	public void setE(EventType e) {
		this.e = e;
	}

	@Override
	public void run() {
		if(e == EventType.APPEND) {
			this.text.append(message);
		} else if(e == EventType.CLEAR) {
			if(text != null) {
				text.setText(null);
			} else {
				field.setText(null);
			}
		} else if(e == EventType.SET_TEXT) {
			field.setText(message);
		}
	}
}
